package com.neuronbit.businessflow.runtime.lifecycle;

import com.neuronbit.businessflow.runtime.Flow;
import com.neuronbit.businessflow.runtime.FlowContext;

/**
 * The interface Flow lifecycle hook.
 */
public interface FlowLifecycleHook {
    /**
     * Support boolean.
     *
     * @param context the context
     * @param flow    the flow
     * @return the boolean
     */
    boolean support(FlowContext context, Flow flow);

    /**
     * flow 是否可重入
     * 如果可重入，则通过、flow id+入参找到上次执行的记录
     * 1. 加载context
     * 2. 加载 step 执行记录
     * 3.
     *
     * @param context the context
     * @param flow    the flow
     */
    void onStart(FlowContext context, Flow flow);

    /**
     * 更新 flow 执行记录：状态=执行完成，输出，执行后的 context，执行耗时
     *
     * @param context the context
     * @param flow    the flow
     */
    void onEnd(FlowContext context, Flow flow);

    /**
     * 更新 flow 执行记录：状态=执行失败，异常信息，异常堆栈，执行耗时，累加执行次数
     *
     * @param context the context
     * @param flow    the flow
     * @param e       the e
     */
    void onError(FlowContext context, Flow flow, Exception e);

    void onPause(FlowContext context, Flow flow);
}
